<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus" v-if="status === '0'">新增</a-button>
    </div>
    <div class="ant-alert ant-alert-info" style="margin-bottom: 16px">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a
        >项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
        <span style="float:right;">
          <a-popover title="自定义列" trigger="click" placement="leftBottom">
            <template slot="content">
              <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
                <a-row style="width: 400px">
                  <template v-for="(item,index) in defColumns">
                    <template v-if="item.key!=='rowIndex'&& item.dataIndex!=='action'">
                        <a-col :span="12"><a-checkbox :value="item.dataIndex"><j-ellipsis :value="item.title" :length="10"></j-ellipsis></a-checkbox></a-col>
                    </template>
                  </template>
                </a-row>
              </a-checkbox-group>
            </template>
            <a><a-icon type="setting" />设置</a >
          </a-popover>
        </span>
      </div>
    <!-- table区域-begin -->
    <div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        class="j-table-force-nowrap1"
        :scroll="{x:true}"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        @change="handleTableChange">
        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)" v-if="status === '0'">编辑</a>
          <a-divider type="vertical" v-if="status === '0'" />
          <a-popconfirm
            v-if="status === '0'"
            title="确定删除吗?"
            @confirm="() => handleDelete(record.id)">
            <a>删除</a>
          </a-popconfirm>
          <a-divider type="vertical" v-if="status === '0'" />
          <a @click="handleDetail(record)" v-if="status === '1'">详情</a>
          <a-divider type="vertical" v-if="status === '1'" />
          <a-popconfirm
            title="确定撤销吗?"
            v-if="status === '1'"
            @confirm="() => handleCancel(record)">
           <a>撤销</a>
          </a-popconfirm>
        </span>
      </a-table>
    </div>

    <inspection-record-modal ref="modalForm" @ok="modalFormOk" />
  </a-card>
</template>

<script>

import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import InspectionRecordModal from './modules/InspectionRecordModal'
import '@/assets/less/TableExpand.less'
import { postAction } from '@api/manage'

export default {
  name: 'InspectionRecordList',
  mixins: [JeecgListMixin],
  components: {
    InspectionRecordModal
  },
  props: {
    status: {
      type: String,
      default: '0'
    }
  },
  data() {
    return {
      description: '巡检记录表管理页面',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '巡检单号',
          align: 'center',
          dataIndex: 'recordNumber'
        },
        {
          title: '巡检标准名称',
          align: 'center',
          dataIndex: 'standardName'
        },
        {
          title: '计划单号',
          align: 'center',
          dataIndex: 'planNumber'
        },
        {
          title: '巡检结果',
          align: 'center',
          dataIndex: 'result_dictText'
        },
        {
          title: '巡检人',
          align: 'center',
          dataIndex: 'createBy_dictText'
        },
        {
          title: '巡检部门',
          align: 'center',
          dataIndex: 'sysOrgCode_dictText'
        },
        {
          title: '巡检时间',
          align: 'center',
          dataIndex: 'createTime',
          customRender: function(text) {
            return !text ? '' : (text.length > 10 ? text.substr(0, 10) : text)
          }
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: '/qms/inspection/inspection-record/list',
        delete: '/qms/inspection/inspection-record/delete',
        deleteBatch: '/qms/inspection/inspection-record/deleteBatch',
        exportXlsUrl: '/qms/inspection/inspection-record/exportXls'
      },
      settingColumns: [],
      dictOptions: {},
      superFieldList: [],
      disableMixinCreated: true
    }
  },
  created() {
    if (this.status) {
      this.queryParam.status = this.status
    }
    this.loadData()
  },
  computed: {},
  methods: {
    handleCancel(record) {
      postAction('/qms/inspection/inspection-record/revoke', { id: record.id })
        .then((res) => {
          if (res.success) {
            this.$message.success(res.message)
            this.loadData()
          } else {
            this.$message.warning(res.message)
          }
        })
    },
    initDictConfig() {
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>